<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="../../back-common.jsp"%>
<%@ include file="/WEB-INF/pages/common/taglib.jsp"%>
		<script type='text/javascript' src="<ls:templateResource item='/resources/common/js/jquery.validate.js'/>"></script>
		<script type='text/javascript' src="<ls:templateResource item='/resources/plugins/ztree/jquery.ztree.core-3.5.min.js'/>"></script>
		<script type='text/javascript' src="<ls:templateResource item='/resources/plugins/ztree/jquery.ztree.excheck-3.5.js'/>"></script>
		<link type="text/css" rel="stylesheet"  href="<ls:templateResource item='/resources/plugins/ztree/zTreeStyle.css'/>" >
<script language="JavaScript" type="text/javascript">

$(document).ready(function(){
		var setting = { check:{}, data:{}, callback:{},view:{} };
		setting.check.enable = true;
		setting.check.chkboxType = {'Y':'ps','N':'ps'};
		setting.check.chkStyle = 'radio';
		setting.check.radioType = 'all';
		setting.check.enable = false;
		setting.view.dblClickExpand = false;
		setting.callback.onClick = clickNode;
		setting.data.simpleData =  { enable: true };
		
		$.fn.zTree.init($("#menuTree"), setting, ${menuList});
		
		//刷新内容
		refreshContent();
		
		$("#search").click(function(){
			$.ajax({
			"url":"${contextPath}/admin/member/right/querycontent", 
			data:  {"name":$("#name").val(), "category":$("#category").val(), "curPageNO": 1 , "appNo": $("#appNo").val() },
			type:'post', 
			dataType : 'html', 
			async : false, //默认为true 异步   
			error: function(jqXHR, textStatus, errorThrown) {
			},
			success:function(retData){
		  		$("#contentframe").html(retData);
			}
			});
		});
	});
	
	function refreshContent(){
		$("#contentframe").load("${contextPath}/admin/member/right/querycontent?curPageNO=${curPageNO}&name=${function.name}&appNo=${function.appNo}&category=${function.category}");
	}
	
	function zhedie(){
		var treeObj = $.fn.zTree.getZTreeObj("menuTree");
		treeObj.expandAll(false);
	}
	
	function expandAll() {
		var treeObj = $.fn.zTree.getZTreeObj("menuTree");
		treeObj.expandAll(true);
	}
	
	function clickNode(event, treeId, treeNode) {
    	var menuId = treeNode.id;
    	$("#contentframe").load("${contextPath}/admin/member/right/querycontent?menuId=" + menuId);
	};
         	
    //加载菜单用于选择
	function loadMenuDialog(){
		var menuId = $("#menuId").val();
/* 		var page = "${contextPath}/admin/member/right/loadFunctionMenu?menuId="+menuId;
    	var setting = { title:"关联权限菜单", id:"RoleMenu",
    				 width:280, height:350,close: function (obj){
    				 		if(obj) {
    				 			$("#menuId").val(obj.menuId);
    				 		}
		                  }};
		art.dialog.open( page, setting ); */
		
		
		
		
		var page = "${contextPath}/admin/member/right/loadFunctionMenu?menuId="+menuId;
		layer.open({
    		  type: 2,
    		  id: "RoleMenu",
    		  title: "关联权限菜单",
    		  area: ['280px','350px'],
    		  content: [page,'no'] //iframe的url，no代表不显示滚动条
    	});
  }
  
   	//加载菜单用于选择
	function loadMenuDialog(menuId){
/* 		var page = "${contextPath}/admin/member/right/loadFunctionMenu?menuId="+menuId;
    	var setting = { title:"关联权限菜单", id:"RoleMenu",  width:280, height:350,close: function (obj){ }};
		art.dialog.open(page, setting ); */
		
		var page = "${contextPath}/admin/member/right/loadFunctionMenu?menuId="+menuId;
		layer.open({
    		  type: 2,
    		  id: "RoleMenu",
    		  title: "关联权限菜单",
    		  area: ['280px','350px'],
    		  content: [page,'no'] //iframe的url，no代表不显示滚动条
    	});
	}
	
	 //建立权限菜单
	function createFuncDialog(){
/* 		var page = "${contextPath}/admin/member/right/load";
    	var setting = { title:"新建权限", id:"createFunc",  width:650, height:400,close: function (obj){ }};
		art.dialog.open(page, setting ); */
		
		var page = "${contextPath}/admin/member/right/load";
		layer.open({
    		  type: 2,
    		  id: "updateFunc",
    		  title: "新建权限",
    		  area: ['650px','400px'],
    		  content: [page,'no'] //iframe的url，no代表不显示滚动条
    });
	}
	
		 //更新权限菜单
	function updateFuncDialog(funcId){
		var page = "${contextPath}/admin/member/right/update/" + funcId;
		layer.open({
    		  type: 2,
    		  id: "updateFunc",
    		  title: "修改权限",
    		  area: ['650px','400px'],
    		  content: [page,'no'] //iframe的url，no代表不显示滚动条
    });
		
	}
	
	function loadMenuDialogByMenuId(menuId){
		var menuId = $("#menuId").val();
		return loadMenuDialog(menuId);
	}
  
	function loadMenuDialogCallBack(menuId,menuName){
			$("#menuId").val(menuId);
			$("#menuName").val(menuName);
	}
	
		//清空选项
	function calcelMenuDialogCallBack(id,menuName){
			$("#menuId").val("");
			$("#menuName").val("");
	}	
	
	 function deleteById(id) {
		//询问框

		 layer.confirm('删除权限？', {
		   btn: ['确定','取消'] //按钮
		 }, function(){
		        $.ajax({
		          	url:"${contextPath}/admin/member/right/delete/"+id,			       
		          	dataType:'html',
		          	type:'post',
		          	async:true,
		          	error: function(jqXHR, textStatus, errorThrown) {
					},
					success:function(retData){
				  		refreshContent();
					}
		          }); 
		   layer.msg('删除成功', {icon: 1});
		 }, function(){
/* 		   layer.msg('也可以这样', {
		     time: 20000, //20s后自动关闭
		     btn: ['明白了', '知道了']
		   }); */
		 });
		 
		 

			        
		}
	
   function pager(curPageNO){
			document.getElementById("curPageNO").value=curPageNO;
			document.getElementById("form1").submit();
		}  
</script>
	<form:form id="form1"  action="${contextPath}/admin/member/right/query" method="post" >
        <table class="${tableclass}" style="width: 100%">
	    <thead>
	    	<tr><th><strong class="am-text-primary am-text-lg">权限管理</strong> /  权限管理 </th></tr>
	    </thead>
	     <tbody><tr><td>
			 <div align="left" style="padding: 3px">
			    <input type="hidden" id="curPageNO"  name="curPageNO" value="<%=request.getAttribute("curPageNO")%>">
						&nbsp; 名称 
						<input class="${inputclass}" type="text" name="name" id="name" maxlength="50" value="${bean.name }" />
							&nbsp; 应用
						<select class="${selectclass}" id="appNo" name="appNo">
								<ls:optionGroup type="select" required="false" cache="true" beanName="APP_NO" selectedValue="${bean.appNo}"/>
						</select>
						
						&nbsp; 权限类型
						<select class="${selectclass}" id="category" name="category">
								<ls:optionGroup type="select" required="false" cache="true" beanName="FUNCTION_CATEGORY" selectedValue="${bean.category}"/>
						</select>
					
						<input type="hidden" id="menuId"  name="menuId"  value="${bean.menuId }"/>
						<!-- 
							&nbsp; 权限菜单	 
						<input type="text" id="menuName"  name="menuName"  value="${bean.menuName }"  onclick="javascript:loadMenuDialog(); return false;"/>
						 -->
						<input class="${btnclass}" type="button" id="search"  value="搜索"/>
							<input class="${btnclass}" type="button" value="创建权限" onclick='javascript:createFuncDialog();'/>
			 </div>
 				</td></tr></tbody>
	    </table>
	</form:form>
	<table style="width: 100%; border: 0px;">
		<tr>
		<td width="180px;" valign="top">
		<fieldset style="padding:10px;border:0px solid #000;margin-top:0px;">
			<legend style="font-size:14px;">[选择菜单]&nbsp;
				<a style="font-weight:bold;" href="javascript:expandAll();void(0);">展开+</a>&nbsp;
				<a style="font-weight:bold;" href="javascript:zhedie();void(0);">折叠-</a>
			</legend>
			<div id="menuContent" style="margin:0;" > 
		   		<ul id="menuTree" class="ztree"></ul>
	     	</div>
		</fieldset>
		</td>
		<td valign="top">
		<div  id="contentframe" align="center"  style="width:100%;"></div>
		</td>
		</tr>
	</table>

	

